from pathlib import Path
from queue import Queue
from utils.general import LOGGER
import cv2 as cv2
from img_process import run2 as run2
from multiprocessing import  Process
from flask import Flask, render_template, Response, request

FILE = Path(__file__).resolve()

ROOT = FILE.parents[0]  # YOLOv5 root directory
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'static/'
genertor_list=[]
genertor=None

@app.route('/uploader')
def uploader():
    print("safdsadfs",genertor)
    data=next(genertor[0])
    print(data)
    return 'asdfsadfdsadf'


@app.route('/get_crop')
def get_crop():
    return "截图"
@app.route('/get_number')
def get_number():
    return "数量"
@app.route('/get_position')
def get_position():
    return "识别框位置"
@app.route('/')
def hello_world():
    return render_template('index.html')

def startServer1():
    print("Starting Main Mock Server1")
    app.run(host='0.0.0.0', threaded=True)


if __name__ == "__main__":

    urllist=['0',ROOT / 'static/test2.mp4']
    process_list = []
    queue=Queue(maxsize=-1)

    for i in range(1):  #开启子进程执行
        p = run2(urllist[i]) #实例化进程对象
        data=p.genertor()
        print("data:",data)
        genertor_list.append(data)
        p.start()
        process_list.append(p)

    genertor=genertor_list[0]
    print("genertor_list",genertor_list)

    p=Process(target=startServer1)
    p.deamon = True
    p.start()
    process_list.append(p)

    for i in process_list:
        p.join()

    print('结束测试')